<?php

/**
 * This is the model class for table "members".
 *
 * The followings are the available columns in table 'members':
 * @property integer $member_id
 * @property string $name
 * @property string $nickname
 * @property string $password
 * @property string $mac_address
 * @property integer $status
 * @property integer $parent_member_id
 */
class Members extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Members the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'members';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('status, parent_member_id, member_type', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>128),
			array('nickname', 'length', 'max'=>45),
			array('password, mac_address', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('member_id, name, nickname, password, mac_address, status, parent_member_id, member_type', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'member_id' => 'Member',
			'name' => 'Name',
			'nickname' => 'Nickname',
			'password' => 'Password',
			'mac_address' => 'Mac Address',
			'status' => 'Status',
			'parent_member_id' => 'Parent Member',
		    'member_type' => 'Member Type'
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('member_id',$this->member_id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('nickname',$this->nickname,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('mac_address',$this->mac_address,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('parent_member_id',$this->parent_member_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}